package com.classmate.main;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class BuddyListAdapter extends BaseAdapter{
	Context context;
	ArrayList<BuddyItems> items;
	LayoutInflater inflater;
	
	public BuddyListAdapter(Context context, ArrayList<BuddyItems> items) {
		this.context = context;
		this.items = items;
		
		this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
	}
	
	public int getCount() {
		return items.size();
	}

	public Object getItem(int pos) {
		return items.get(pos);
	}

	public long getItemId(int pos) {
		return pos;
	}

	public View getView(int pos, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = inflater.inflate(R.layout.buddy_list_sub, null);
		}
		ImageView profileImage = (ImageView)convertView.findViewById(R.id.buddy_profile_img);
		TextView nameText = (TextView)convertView.findViewById(R.id.buddy_name_text);
		TextView introText = (TextView)convertView.findViewById(R.id.buddy_intro_text);
		TextView recentlyDateText = (TextView)convertView.findViewById(R.id.buddy_recently_time);
		TextView addrText = (TextView)convertView.findViewById(R.id.buddy_addr_text);
		
		Log.e("adapter","adapter");
		
		profileImage.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
		nameText.setText(items.get(pos).getName());
		introText.setText(items.get(pos).getIntro());
		recentlyDateText.setText(items.get(pos).getRecentlyDate());
		addrText.setText(items.get(pos).getAddress());
		
		return convertView;
	}

}
